package com.zsc.newbuds.controller.admin;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import	java.util.ArrayList;

import com.zsc.newbuds.entity.RecyclingArea;
import com.zsc.newbuds.service.impl.RecyclingAreaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author D
 */

@RequestMapping("admin/areaManagement")
@Controller
public class AreaController {

    @Autowired
    RecyclingAreaServiceImpl recyclingAreaService;

    @ResponseBody
    @GetMapping("/getRecyclingAreaList")
    public List<RecyclingArea> getRecyclingAreaList(){
        return recyclingAreaService.getAreaList();
    }

    @ResponseBody
    @PostMapping("/getRecyclingAreaList")
    public int test(String province,String city,String neighbourhood){
        System.out.println(province+city+neighbourhood);
        Date date = new Date();
        System.out.println(date);
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(date);
        return 1;
    }

    @ResponseBody
    @PostMapping("/addRecyclingArea")
    public void addRecyclingArea(String province,String city,String neighbourhood){
        System.out.println(province+city+neighbourhood);
        Date date = new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(date);

        RecyclingArea recyclingArea = new RecyclingArea();
        recyclingArea.setProvince(province);
        recyclingArea.setCity(city);
        recyclingArea.setNeighbourhood(neighbourhood);
        recyclingArea.setAddTime(time);
        recyclingAreaService.addRecyclingArea(recyclingArea);
    }
}
